package com.cvte.boe.media.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

import com.cvte.boe.media.MediaApplication;


/**
 * Created by user on 2018/4/9.
 */
public class GlobalDialog extends Dialog {

    private static GlobalDialog instance = null;

    private GlobalDialog(Context context) {
        super(context);
    }

    private GlobalDialog(Context context, int theme) {
        super(context, theme);
    }

    private GlobalDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public static GlobalDialog getInstance(Context context) {
        if (instance == null) {
            synchronized (GlobalDialog.class) {
                if (instance == null) {
                    instance = new GlobalDialog(context);
                    instance.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    instance.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                }
            }
        }
        return instance;
    }
    public static void destroyInstance(){
        synchronized (GlobalDialog.class) {
            if(instance != null) {
                instance = null;
            }
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_MENU){
            this.dismiss();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
